//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <fstream>

#include "ListBindingSitePredictionWeighted.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  ListBindingSitePredictionWeighted* listBindingSitePredictionWeighted  = NULL;

  if (argc < 3) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./OutWeightModelToFile <XML filename with models summary>";
    cout <<                       " <Models Scheme>";
    cout <<                            " <Weight Filename>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    listBindingSitePredictionWeighted = new ListBindingSitePredictionWeighted ();
    
    listBindingSitePredictionWeighted->FilenameXMLModels()->In(argv[1]);
    listBindingSitePredictionWeighted->XMLModels()->FilenameIn()->In(argv[1]);
    listBindingSitePredictionWeighted->Scheme()->In(argv[2]);
    
    cout << "---------------------------------------------------------------------------------" << endl;
    cout << "   XML filename with models summary : " << argv[1] << endl;
    cout << "                      Models Scheme : " << argv[2] << endl;
    cout << "                 Histogram Filename : " << argv[3] << endl;
    cout << "---------------------------------------------------------------------------------" << endl;
    
  }
  
  cout << "Loading data..." << endl;
  if (!listBindingSitePredictionWeighted->XMLModels()->LoadXMLFile())
    cout << "Error loading data..." << endl;

  if (!listBindingSitePredictionWeighted->LoadWeight())
    cout << "Error loading data..." << endl;
    
  cout << "Writing the weight of the model to the file..." << endl;
  ofstream file (argv[3]);
  
  if (file.is_open()) {
    
    listBindingSitePredictionWeighted->Weights()->Patterns()->SetInitial();
    while (listBindingSitePredictionWeighted->Weights()->Patterns()->SetNext())
      if (strcmp(listBindingSitePredictionWeighted->Weights()->Patterns()->GetCurrent()->Type()->Out(), "Correction") != 0)
        file << listBindingSitePredictionWeighted->Weights()->Patterns()->GetCurrent()->Weight() << endl;      
    
    file.close();
    
  }
    
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (listBindingSitePredictionWeighted) delete listBindingSitePredictionWeighted;
  
  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

